using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_ClientRelation_ContacterManage : Member, IRequiresSessionState
{
	public string m_flag = "0";
	private string linkHead = "";
	private string tabMenu = "";
	private string actionTab = "";
	private int contacID = 0;
	protected ScriptManager ScriptManager1;
	protected Label lblContacterManage;
	protected Label lblAddOrEditContacter;
	protected HiddenField hfClientID;
	protected HiddenField hfContacterID;
	protected DropDownList ddl_ClientType;
	protected TextBox txtSearchClientName;
	protected TextBox txtSearchTrueName;
	protected Button SeachBut;
	protected GridView gvContacterManage;
	protected Literal ltrPagePanel;
	protected Button btnMoreDelete;
	protected PlaceHolder phContacterManage;
	protected TextBox txtClient;
	protected HtmlAnchor showClient;
	protected HiddenField hfDuiYingKeHu;
	protected TextBox txtTitle;
	protected TextBox txtTrueName;
	protected RegularExpressionValidator revTrueName;
	protected TextBox txtOperation;
	protected TextBox txtDepartment;
	protected TextBox txtPosition;
	protected DropDownList ddlCountry;
	protected Shop_UserControls_HowaveProvinceCity HoWaveProvinceCity1;
	protected TextBox txtAddress;
	protected TextBox txtZipCode;
	protected RegularExpressionValidator revZipCode;
	protected TextBox txtOfficePhone;
	protected TextBox txtHomePhone;
	protected TextBox txtMobile;
	protected TextBox txtFax;
	protected TextBox txtHomepage;
	protected TextBox txtEmail;
	protected TextBox txtQQ;
	protected TextBox txtMSN;
	protected TextBox txtYahoo;
	protected TextBox txtUC;
	protected TextBox txtBirthday;
	protected TextBox txtIDCard;
	protected TextBox txtNativePlace;
	protected TextBox txtNation;
	protected RadioButtonList rblSex;
	protected RadioButtonList rblMarriage;
	protected DropDownList ddlEducation;
	protected TextBox txtGraduateFrom;
	protected TextBox txtInterestsOfLife;
	protected TextBox txtInterestsOfCulture;
	protected TextBox txtInterestsOfAmusement;
	protected TextBox txtInterestsOfSport;
	protected TextBox txtInterestsOfOther;
	protected DropDownList ddlIncome;
	protected TextBox txtFamily;
	protected Button btnSave;
	protected PlaceHolder phContacterAddOrEdit;
	public string TabMenu
	{
		get
		{
			if (base.Request.QueryString["TabMenu"] != null)
			{
				this.tabMenu = base.Request.QueryString["TabMenu"].Trim();
			}
			return this.tabMenu;
		}
		set
		{
			this.tabMenu = value;
		}
	}
	public string ActionTab
	{
		get
		{
			if (base.Request.QueryString["action"] != null)
			{
				this.actionTab = base.Request.QueryString["action"].Trim();
			}
			else
			{
				this.actionTab = "";
			}
			return this.actionTab;
		}
		set
		{
			this.actionTab = value;
		}
	}
	public int ContacID
	{
		get
		{
			if (base.Request.QueryString["contacterID"] != null)
			{
				this.contacID = Convert.ToInt32(base.Request.QueryString["contacterID"].Trim());
			}
			return this.contacID;
		}
		set
		{
			this.contacID = value;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPowerClientRelation(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(this.TabMenu);
			this.BindRadioButtonList();
			this.BindDropDownList();
			this.BindClientContacter();
			if (this.ContacID > 0)
			{
				this.InitPage();
			}
		}
		else
		{
			this.m_flag = Cookie.GetCookie("Contacter_m_flag");
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (!(DisplayName == "tabMnage"))
			{
				if (DisplayName == "tabAdd")
				{
					this.m_flag = "1";
					this.phContacterManage.Visible = false;
					this.phContacterAddOrEdit.Visible = true;
					this.showClient.Attributes.Add("onclick", "SelectClient('" + this.txtClient.ClientID + "');");
					if (this.ActionTab == "addinfo")
					{
						this.lblAddOrEditContacter.Text = "添加联系人";
						if (base.Request.QueryString["clientname"] != null)
						{
							this.txtClient.Text = base.Request.QueryString["clientname"].ToString();
						}
					}
					else
					{
						if (this.ActionTab == "editinfo")
						{
							this.lblAddOrEditContacter.Text = "修改联系人";
						}
					}
				}
			}
			else
			{
				this.m_flag = "0";
				this.phContacterManage.Visible = true;
				this.phContacterAddOrEdit.Visible = false;
			}
		}
		Cookie.SaveCookie("Contacter_m_flag", this.m_flag, 0, "");
	}
	protected void BindRadioButtonList()
	{
		this.rblSex.bindDataToRadioButtonList("HL_ClientContacter", "Sex", true);
		this.rblMarriage.bindDataToRadioButtonList("HL_ClientContacter", "Marriage", true);
	}
	protected void BindDropDownList()
	{
		this.ddl_ClientType.bindDataToDropDownList("HL_Client", "ClientType", false, false);
		this.ddlEducation.bindDataToDropDownList("HL_ClientContacter", "Education", true, false);
		this.ddlIncome.bindDataToDropDownList("HL_ClientContacter", "Income", true, false);
	}
	protected HoWave.Data.Model.ClientContacter GetClientContacter()
	{
		HoWave.Data.Model.ClientContacter clientContacter = new HoWave.Data.Model.ClientContacter();
		string text = this.txtClient.Text.Trim();
		string text2 = this.txtTrueName.Text;
		string text3 = this.txtTitle.Text;
		string text4 = this.txtDepartment.Text;
		string text5 = this.txtPosition.Text;
		string text6 = this.txtOperation.Text;
		clientContacter.TrueName = text2;
		clientContacter.Title = text3;
		clientContacter.Department = text4;
		clientContacter.Position = text5;
		clientContacter.Operation = text6;
		string text7 = this.ddlCountry.Text;
		string selectedProvince = this.HoWaveProvinceCity1.SelectedProvince;
		string selectedCity = this.HoWaveProvinceCity1.SelectedCity;
		string selectedArea = this.HoWaveProvinceCity1.SelectedArea;
		string text8 = this.txtAddress.Text;
		string text9 = this.txtZipCode.Text;
		string text10 = this.txtOfficePhone.Text;
		string text11 = this.txtHomePhone.Text;
		string text12 = this.txtMobile.Text;
		string text13 = this.txtFax.Text;
		string text14 = this.txtHomepage.Text;
		string text15 = this.txtEmail.Text;
		string text16 = this.txtQQ.Text;
		string text17 = this.txtMSN.Text;
		string text18 = this.txtYahoo.Text;
		string text19 = this.txtUC.Text;
		clientContacter.Country = text7;
		clientContacter.Province = selectedProvince;
		clientContacter.City = selectedCity;
		clientContacter.Districts = selectedArea;
		clientContacter.Address = text8;
		clientContacter.ZipCode = text9;
		clientContacter.OfficePhone = text10;
		clientContacter.HomePhone = text11;
		clientContacter.Mobile = text12;
		clientContacter.Fax = text13;
		clientContacter.Homepage = text14;
		clientContacter.Email = text15;
		clientContacter.QQ = text16;
		clientContacter.MSN = text17;
		clientContacter.Yahoo = text18;
		clientContacter.UC = text19;
		string text20 = this.txtBirthday.Text.Trim();
		string text21 = this.txtIDCard.Text;
		string text22 = this.txtNativePlace.Text;
		string text23 = this.txtNation.Text;
		string selectedValue = this.rblSex.SelectedValue;
		string selectedValue2 = this.rblMarriage.SelectedValue;
		string selectValue = this.ddlEducation.GetSelectValue(new string[0]);
		string text24 = this.txtGraduateFrom.Text;
		string text25 = this.txtInterestsOfLife.Text;
		string text26 = this.txtInterestsOfCulture.Text;
		string text27 = this.txtInterestsOfAmusement.Text;
		string text28 = this.txtInterestsOfSport.Text;
		string text29 = this.txtInterestsOfOther.Text;
		string selectValue2 = this.ddlIncome.GetSelectValue(new string[0]);
		string text30 = this.txtFamily.Text;
		DateTime now = DateTime.Now;
		DateTime now2 = DateTime.Now;
		if (!string.IsNullOrEmpty(text20))
		{
			clientContacter.Birthday = new DateTime?(DateTime.Parse(text20));
		}
		clientContacter.IDCard = text21;
		clientContacter.NativePlace = text22;
		clientContacter.Nation = text23;
		clientContacter.Sex = Convert.ToInt32(selectedValue);
		clientContacter.Marriage = Convert.ToInt32(selectedValue2);
		clientContacter.Education = selectValue;
		clientContacter.GraduateFrom = text24;
		clientContacter.InterestsOfLife = text25;
		clientContacter.InterestsOfCulture = text26;
		clientContacter.InterestsOfAmusement = text27;
		clientContacter.InterestsOfSport = text28;
		clientContacter.InterestsOfOther = text29;
		clientContacter.Income = selectValue2;
		clientContacter.Family = text30;
		clientContacter.CreateTime = new DateTime?(now);
		clientContacter.UpdateTime = new DateTime?(now2);
		clientContacter.Owner = base.user.UserID;
		return clientContacter;
	}
	private bool CheckInput()
	{
		bool result = true;
		string text = this.txtOfficePhone.Text.Trim();
		if (text != "")
		{
			if (!PageValidate.CheckHomePhome(text))
			{
				this.txtOfficePhone.Focus();
				MessageBox.Show(this, "办公电话格式不对");
				result = false;
			}
		}
		string text2 = this.txtHomePhone.Text.Trim();
		if (text2 != "")
		{
			if (!PageValidate.CheckHomePhome(text2))
			{
				this.txtHomePhone.Focus();
				MessageBox.Show(this, "住宅电话格式不对");
				result = false;
			}
		}
		string text3 = this.txtMobile.Text.Trim();
		if (text3 != "")
		{
			if (!PageValidate.CheckMobile(text3))
			{
				this.txtMobile.Focus();
				MessageBox.Show(this, "移动电话格式不对");
				result = false;
			}
		}
		string text4 = this.txtEmail.Text.Trim();
		if (text4 != "")
		{
			if (!PageValidate.IsEmail(text4))
			{
				this.txtEmail.Focus();
				MessageBox.Show(this, "Email地址格式不对");
				result = false;
			}
		}
		string text5 = this.txtIDCard.Text.Trim();
		if (text5 != "")
		{
			if (!PageValidate.CheckIDCard(text5))
			{
				this.txtIDCard.Focus();
				MessageBox.Show(this, "证件号码格式不对");
				result = false;
			}
		}
		return result;
	}
	protected void InitPage()
	{
		HoWave.Data.Model.ClientContacter model = HoWave.Data.Bll.ClientContacter.instance.GetModel(this.ContacID);
		if (model != null)
		{
			this.hfContacterID.Value = this.ContacID.ToString();
			HoWave.Data.Model.Client model2 = HoWave.Data.Bll.Client.instance.GetModel((int)Convert.ToInt16(model.ClientID));
			if (model2 != null)
			{
				this.txtClient.Text = model2.ClientName;
				this.hfDuiYingKeHu.Value = model2.ClientID.ToString();
			}
			this.txtTrueName.Text = model.TrueName;
			this.txtTitle.Text = model.Title;
			this.txtDepartment.Text = model.Department;
			this.txtPosition.Text = model.Position;
			this.txtOperation.Text = model.Operation;
			this.ddlCountry.ddlSelect(model.Company);
			this.HoWaveProvinceCity1.SelectedProvince = model.Province;
			this.HoWaveProvinceCity1.SelectedCity = model.City;
			this.HoWaveProvinceCity1.SelectedArea = model.Districts;
			this.txtAddress.Text = model.Address;
			this.txtZipCode.Text = model.ZipCode;
			this.txtOfficePhone.Text = model.OfficePhone;
			this.txtHomePhone.Text = model.HomePhone;
			this.txtMobile.Text = model.Mobile;
			this.txtFax.Text = model.Fax;
			this.txtHomepage.Text = model.Homepage;
			this.txtEmail.Text = model.Email;
			this.txtQQ.Text = model.QQ;
			this.txtMSN.Text = model.MSN;
			this.txtYahoo.Text = model.Yahoo;
			this.txtUC.Text = model.UC;
			this.txtBirthday.Text = "";
			if (model.Birthday.HasValue)
			{
				this.txtBirthday.Text = model.Birthday.ToString();
			}
			this.txtBirthday.Text = model.Birthday.ToString();
			this.txtIDCard.Text = model.IDCard;
			this.txtNativePlace.Text = model.NativePlace;
			this.txtNation.Text = model.Nation;
			this.rblSex.rblSelect(model.Sex.ToString());
			this.rblMarriage.rblSelect(model.Marriage.ToString());
			this.ddlEducation.ddlSelect(model.Education);
			this.txtGraduateFrom.Text = model.GraduateFrom;
			this.txtInterestsOfLife.Text = model.InterestsOfLife;
			this.txtInterestsOfCulture.Text = model.InterestsOfCulture;
			this.txtInterestsOfAmusement.Text = model.InterestsOfAmusement;
			this.txtInterestsOfSport.Text = model.InterestsOfSport;
			this.txtInterestsOfOther.Text = model.InterestsOfOther;
			this.ddlIncome.ddlSelect(model.Income);
			this.txtFamily.Text = model.Family;
		}
	}
	protected int GetClientId(string clientName)
	{
		int result = 0;
		HoWave.Data.Model.Client clientByClientName = HoWave.Data.Bll.Client.instance.GetClientByClientName(clientName, base.user.UserID);
		if (clientByClientName != null)
		{
			result = clientByClientName.ClientID;
		}
		return result;
	}
	protected void btnSave_Click(object sender, EventArgs e)
	{
		if (this.Page.IsValid && this.CheckInput())
		{
			int clientId = this.GetClientId(this.hfDuiYingKeHu.Value.Trim());
			if (clientId > 0)
			{
				HoWave.Data.Model.ClientContacter clientContacter = this.GetClientContacter();
				clientContacter.ClientID = new int?(clientId);
				if (this.ActionTab == "addinfo")
				{
					int num = HoWave.Data.Bll.ClientContacter.instance.Add(clientContacter);
					if (num > 0)
					{
						this.WriteSuccessMsg("", "添加联系人信息成功！", "ContacterManage.aspx?TabMenu=tabMnage");
					}
					else
					{
						this.WriteErrMsg("", "添加联系人信息失败！", "");
					}
				}
				else
				{
					if (this.ActionTab == "editinfo")
					{
						clientContacter.ContacterID = Convert.ToInt32(this.hfContacterID.Value);
						bool flag = HoWave.Data.Bll.ClientContacter.instance.Update(clientContacter);
						if (flag)
						{
							this.WriteSuccessMsg("", "更新联系人信息成功！", "ContacterManage.aspx?TabMenu=tabMnage");
						}
						else
						{
							this.WriteErrMsg("", "更新联系人信息失败！", "");
						}
					}
				}
			}
		}
	}
	protected void BindClientContacter()
	{
		string query = this.GetQuery();
		int num = this.gvContacterManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HL_Client as c,HL_ClientContacter as cc where cc.ClientID=c.ClientID and cc.Owner=" + base.user.UserID + " ";
		int pageSize = this.gvContacterManage.PageSize;
		int listCount = HoWave.Data.Bll.ClientContacter.instance.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "c.GroupID,c.ClientType,c.ClientName,ROW_NUMBER() OVER (order by cc.ContacterID desc) as row,cc.* ";
		string strSQL = "select " + str + text + query;
		DataTable contacterListByPage = HoWave.Data.Bll.ClientContacter.instance.GetContacterListByPage(strSQL, "row", startIndex, endIndex);
		this.gvContacterManage.DataSource = contacterListByPage;
		this.gvContacterManage.DataBind();
		string url = "ContacterManage.aspx?TabMenu=tabMnage" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ClientType");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddl_ClientType.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddl_ClientType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and ClientType='" + text2 + "'";
			this.linkHead = this.linkHead + "&ClientType=" + text2;
		}
		string text3 = Fetch.Get("KeHuName");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchClientName.Text = text3;
		}
		else
		{
			text3 = this.txtSearchClientName.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and c.ClientName like '%" + text3 + "%'";
			this.linkHead = this.linkHead + "&KeHuName=" + text3;
		}
		string text4 = Fetch.Get("TrueName");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchTrueName.Text = text4;
		}
		else
		{
			text4 = this.txtSearchTrueName.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and cc.TrueName like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&TrueName=" + text4;
		}
		return text;
	}
	protected string GetDictionaryTitle(string fieldValue)
	{
		string result = "";
		HoWave.Data.Model.Dictionary dictionary = HoWave.Data.Bll.Dictionary.instance.GetDictionary(fieldValue);
		if (dictionary != null)
		{
			result = dictionary.FieldText;
		}
		return result;
	}
	protected string GetContacPhone(string officePhone, string homephome, string mobile)
	{
		string text = "";
		if (!string.IsNullOrEmpty(officePhone))
		{
			text = text + "办公：" + officePhone + "<br>";
		}
		if (!string.IsNullOrEmpty(homephome))
		{
			text = text + "住宅：" + homephome + "<br>";
		}
		if (!string.IsNullOrEmpty(mobile))
		{
			text = text + "手机：" + mobile;
		}
		return text;
	}
	protected void gvContacterManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvContacterManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvContacterManage.PageIndex = e.NewPageIndex;
		this.BindClientContacter();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		if (commandName == "MoreDelete")
		{
			string text = Text.CheckNumList(Fetch.GetOrPost("contacterSelect"));
			if (text != "")
			{
				bool flag = false;
				string text2 = text;
				string[] array = text2.Split(new char[]
				{
					','
				});
				for (int i = 0; i < array.Length; i++)
				{
					flag = HoWave.Data.Bll.ClientContacter.instance.DeleteList(array[i]);
				}
				if (flag)
				{
					this.WriteErrMsg("", "批量信息删除成功！", "ContacterManage.aspx?TabMenu=tabMnage" + this.linkHead + "&pageindex");
				}
			}
			else
			{
				this.WriteErrMsg("", "请选您要删除的信息", "");
			}
		}
		else
		{
			if (commandName == "CheckInfo")
			{
				string text3 = e.CommandArgument.ToString();
				if (!string.IsNullOrEmpty(text3))
				{
					base.Response.Redirect("ContacterDetailInfo.aspx?contacterID=" + text3);
				}
			}
			else
			{
				if (commandName == "EditInfo")
				{
					string text3 = e.CommandArgument.ToString();
					if (!string.IsNullOrEmpty(text3))
					{
						base.Response.Redirect("ContacterManage.aspx?TabMenu=tabAdd&action=editinfo&contacterID=" + text3);
					}
				}
				else
				{
					if (commandName == "DelInfo")
					{
						string text3 = e.CommandArgument.ToString();
						HoWave.Data.Model.ClientContacter model = HoWave.Data.Bll.ClientContacter.instance.GetModel(Convert.ToInt32(text3));
						if (model != null)
						{
							bool flag2 = HoWave.Data.Bll.ClientContacter.instance.Delete(Convert.ToInt32(text3));
							if (flag2)
							{
								this.WriteErrMsg("", "删除成功！", "ContacterManage.aspx?TabMenu=tabMnage" + this.linkHead + "&pageindex");
							}
						}
					}
				}
			}
		}
		this.BindClientContacter();
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.m_flag = "0";
		this.BindClientContacter();
	}
}
